﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace WindowsGame1.Controller
{
    class MasterController
    {
        //fält
        private Controller.GameController   _gameController;
        private Controller.MenuController   _menuController;
        private Controller.IController      _controllerToUse;

        private GraphicsDeviceManager       _manager;
        private ContentManager              _contentManager;
        
        //Konstruktor
        public MasterController(GraphicsDeviceManager a_manager, ContentManager a_contentManager)
        {
            _menuController = new MenuController(a_manager, a_contentManager);
            _gameController = new GameController(a_manager, a_contentManager);
            _controllerToUse = _menuController;

            _manager = a_manager;
            _contentManager = a_contentManager;
        }

        //metod som uppdaterar och kollar om man byter kontroller
        internal void Update(float a_elapsedTime)
        {
            _controllerToUse.Update(a_elapsedTime);

            if (_controllerToUse.DidUserChangeController() == true)
            {
                if (_controllerToUse == _gameController)
                {
                    _controllerToUse = _menuController;
                }
                else
                {
                    RestartGame();
                    _controllerToUse = _gameController;
                }
            }
        }

        //Funtion för att starta om spelet
        private void RestartGame()
        {
            _gameController = new GameController(_manager, _contentManager);
        }

        //Metod som anropar vyns draw metod.
        public void Draw(float a_elapsedTime, Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice)
        {
            _controllerToUse.Draw(a_elapsedTime, GraphicsDevice);
        }
    }
}
